package cn.bugDance.domain.activity.service.rule.factory;

import cn.bugDance.domain.activity.model.entity.ActivityCountEntity;
import cn.bugDance.domain.activity.model.entity.ActivityEntity;
import cn.bugDance.domain.activity.model.entity.ActivitySkuEntity;
import cn.bugDance.domain.activity.model.valobj.ActivityConstant;
import cn.bugDance.domain.activity.service.rule.IRuleChain;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component("activityRuleChainFactory")
public class RuleChainFactory {

    private Map<String, IRuleChain> ruleChainGroup;

    public RuleChainFactory(Map<String, IRuleChain> ruleChainGroup) {
        this.ruleChainGroup = ruleChainGroup;
    }

    public void openRuleChain(ActivityEntity activityEntity, ActivityCountEntity activityCountEntity, ActivitySkuEntity activitySkuEntity){
        IRuleChain ruleActivitySkuStockChain = ruleChainGroup.get(ActivityConstant.ActivityRule.RULE_SKU_STOCK);
        IRuleChain ruleActivityStateChain = ruleChainGroup.get(ActivityConstant.ActivityRule.RULE_ACTIVITY_STATE);

        ruleActivityStateChain.appendNext(ruleActivitySkuStockChain);

        ruleActivityStateChain.action(activityEntity, activitySkuEntity, activityCountEntity);
    }
}
